package com.itheima.mp.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mp.domain.po.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

//@SpringBootTest
public class LambdaWrapper {
    @Autowired
    private UserMapper userMapper;

    @Test
    public void testQueryLambdaWrapper() {
        //使用lambda方法引用，简化语句而且不会写死参数；
           /*
           *    * 查询除名字中带o，存款大于等于1000元的人的id，username，info，balance
                * select id,username,info,balance
                * from user
                * where username like ? and balance >= ?
         */
        LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<User>()
                .select(User::getId,User::getUsername,User::getInfo,User::getBalance)
                .like(User::getUsername,"o")
                .ge(User::getBalance,1000);
        List<User> users = userMapper.selectList(queryWrapper);
        users.forEach(System.out::println);
    }
}
